package com.zito.health.common.service.impl;

import com.zito.health.common.constant.BaseConstant;
import com.zito.health.common.entity.BaseEntity;
import com.zito.health.common.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.common.Mapper;

import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: gxt
 * @time: 2019/10/12 10:36
 */
public abstract class BaseServiceImpl<T> implements BaseService<T> {

    @Autowired
    private Mapper<T> mapper;

    @Override
    public T save(T object) {
        int res = mapper.insertSelective(object);
        return object;
    }

    @Override
    public void delete(Integer id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(T object) {
        mapper.updateByPrimaryKeySelective(object);
    }

    @Override
    public List<T> query() {
        return mapper.selectAll();
    }

    @Override
    public List<T> query(T object) {
        return mapper.select(object);
    }

    @Override
    public T queryOne(T object) {
        return mapper.selectOne(object);
    }

    @Override
    public T queryById(Integer id) {
        T object = mapper.selectByPrimaryKey(id);
        return object;
    }

    @Override
    public boolean exists(Integer id) {
        return mapper.existsWithPrimaryKey(id);
    }
}
